<template>
	<view>
		<view class="goods-item">
			<view class="goods-left">
				<radio :checked="goods.goods_state" color="#f00000" v-if="showRadio" @click="radioClickHandler"></radio>
				<image class='goods-img' :src="goods.goods_small_logo || defaultImg" @click="test" mode=""></image>
			</view>
			<view class="goods-right">
				<view class="goods-name">{{goods.goods_name}}</view>
				<view class="goods-price-num">
					<view class="goods-price">￥{{goods.goods_price | toFixed}}</view>
					<uni-number-box background="#FFFFFF" :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeValue"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import {mapMutations} from "vuex";
	export default {
		name:"goods_item",
		props:{
			goods:{
				type:Object,
				default:{}
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			showNum:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				defaultImg:"http://image3.suning.cn/uimg/b2c/newcatentries/0070061155-000000000617064184_1_200x200.jpg"
			};
		},
		filters:{
			toFixed(num){
				return Number(num).toFixed(2);
			}
		},
		methods:{
			test(){
				this.$emit("click");
			},
			// ...mapMutations('cart_m',['updateGoodsState']),
			radioClickHandler(){
				console.log('点击radio');
				const goods_id_state = {
					goods_id:this.goods.goods_id,
					//goods_state最新值
					goods_state:!this.goods.goods_state,
				}
				//获取最新的数据 和 方法
				// this.updateGoodsState(goods_id_state);
				this.$emit('radioChange',goods_id_state);
			},
			numChangeValue(value){
				console.log(value);
				// 最新的value值  goods_id传递给父级 子传父
				this.$emit('numChange',{
					goods_id:this.goods.goods_id,
					goods_count:value
				})
			}
		}
	}
</script>

<style lang="scss">
.goods-item{
	display: flex;
	padding: 10px;
	border-bottom: 1px solid #ececec;
	.goods-left{
		margin-right: 10px;
		display: flex;
		align-items: center;
		.goods-img{
			width: 200rpx;
			height: 200rpx;
			display: block;
		}
	}
	
	.goods-right{
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.goods-name{
			font-size: 26rpx;
		}
		
		.goods-price-num{
			display: flex;
			align-items: center;
			justify-content: space-between;
			
			.goods-price{
				font-size: 36rpx;
				color: #c00000;
			}
			uni-number-box{
				border: 1px solid #F0F0F0;
			}
		}
	}
}
</style>
